'abuphysics.monkey by Belimoth
Strict
Import abu.abutime
'TODO
'	optional collision masks
'	optional integration with Box2D or Nape
'	one int doesn't allow for a one-category per entity type scenario

Const COLLIDE_NONE:Int = 0
Const COLLIDE_SELF:Int = 1
Const COLLIDE_GRID:Int = 2		'rename COLLIDE_TILE?
Const COLLIDE_FRAME:Int = 4
Const COLLIDE_ALL:Int = $FFFFFFFF
Global COLLIDE_DEFAULT:Int = COLLIDE_SELF | COLLIDE_GRID | COLLIDE_FRAME

Interface IPhysics
	'Method PreMove:Void()
	'Method StepMovement:Void()
	'Method PostMove:Void()		'move this junk into HandleTrace?
	
	'Method OnCollision:Void(other:IPhysics)
	'Method HandleTrace:Void(result:TraceResult)
End

Class TraceResult

End

Class Physics

End

Class PhysicsComponent Extends EntityComponent Implements IPhysics
	Field dx:Int 'Field xDisplacementThisFrame:Int
	Field dy:Int 'Field yDisplacementThisFrame:Int
	
	Method PreMove:Void()
		dx = owner.velocityComponent.xDisplacement
		dy = owner.velocityComponent.yDisplacement
	End
	
	Method StepMovement:Void()				'put this void so it would compile
		owner.positionComponent
	End
End

Class CollisionGroup

	Field categoryBits:Int
	Field maskBits:Int
	
	Method New(maskBits:Int = COLLIDE_DEFAULT)
		Self.categoryBits = AllocateCategory()
		If (maskBits & COLLIDE_SELF)
			maskBits |= Self.categoryBits
		Endif
		Self.maskBits = maskBits
	End
	
	Method New(participant:IPhysics, maskBits:Int = COLLIDE_DEFAULT)			'added this IPhysics so it would compile
	
	End
	
	Method ToInt:Int()
		Return categoryBits
	End
	
Private
	Global currentBits:Int = 8	
	
	Function AllocateCategory:Int()
		Local bitsTemp:Int = currentBits
		curentBits = currentBits * 2
		Return bitsTemp
	End
End

Class PhysicsHandler
	Field participants:List<IPhysics>			'added this IPhysics so it would compile
	
	Method Evaluate:Void()
End
	
